<template>
    <!-- 运输管理措施 -->
    <div>
        <div class="basicCell">
            <div class="basicCellTitle">运输管理措施</div>
            

                <div class="basicSubtitle" v-if="isDisabled">
                    <el-button type="primary" @click="addTrans">新增</el-button>
                </div>
                
                    <el-table border fit empty-text="暂无数据" :data="formData.tableDataTrans">
                        <el-table-column label="运输公司名称" align="center" prop="nameGS" />
                        <el-table-column label="负责人" align="center" prop="userName" />
                        <el-table-column label="联系电话" align="center" prop="phone"/>
                        <!-- <el-table-column label="运输路线" align="center" prop="areaName" width="80" /> -->
                        <el-table-column label="车辆信息" align="center" prop="carInfor" />
                        <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" >
                            <template slot-scope="scope">
                            <el-button size="mini" type="text" icon="el-icon-edit" @click="updateTrans(scope.row, scope.$index)" >修改</el-button>
                            <el-button size="mini" type="text" icon="el-icon-delete" @click="deleteTrans(scope.row, scope.$index)" >删除</el-button>
                            <el-button size="mini" type="text" icon="el-icon-delete" @click="descTrans(scope.row, scope.$index)" >详情</el-button>
                            
                            </template>
                        </el-table-column>
                    </el-table>
            
            <el-dialog :title="titleTrans" :visible.sync="openTrans" width="800px" append-to-body>
                <el-form ref="formBasic" :rules="rulesTrans" label-width="100px">
                    <!-- <div class="basicSubtitle">基础信息</div> -->
                    <el-row>
                        <el-col :span="12">
                        <el-form-item label="运输公司名称" prop="name">
                            <el-input :disabled="isDesc" v-model="formDataTrans.nameGS" :placeholder="请输入运输公司名称" />
                        </el-form-item>
                        </el-col>
                        <el-col :span="12">
                        <el-form-item label="负责人" prop="userName">
                            <el-input :disabled="isDesc" v-model="formDataTrans.userName" placeholder="请输入负责人" />
                        </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="联系电话" prop="phone">
                                <el-input :disabled="isDesc" v-model="formDataTrans.phone" placeholder="请输入联系电话" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="车辆信息" prop="carInfor">
                                <el-select :disabled="isDesc" class="fillUp" v-model="formDataTrans.carInfor" clearable placeholder="请选择车辆信息">
                                    <el-option
                                        v-for="(v,index) in carInforList"
                                        :key="index"
                                        :label="v.label"
                                        :value="v.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item label="运输路线" prop="transLine">
                                <el-input :disabled="isDesc" v-model="formDataTrans.transLine" placeholder="请输入建设单位" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="submitTrans">确 定</el-button>
                </div>
            </el-dialog>
        </div>
        <div class="baAddRightBtm">
            <el-button type="primary" @click="next">暂存</el-button>
            <el-button type="primary" v-if="stepActive != 0" @click="back">上一步</el-button>
            <el-button type="primary" v-if="stepActive < 3" @click="next">下一步</el-button>
            <el-button type="primary" v-if="stepActive == 3" @click="next">确认</el-button>
        </div>
    </div>
  </template>
  
  <script>
  export default {
    name: "Record",
    props: {
        isDisabled: {
            type: Boolean,
            default: false
        },
        provinceList: {
            default: []
        }
    },
    components: {  },
    data() {
      return {
        stepActive: 0, // 进度
        formData: { // 表单数据
            tableDataTrans: []
        }, 
        rulesBasic: null, // 校验
        typeList: [],
        // 运输公司字段信息 ====================
        titleTrans: '', // 弹窗标题
        openTrans: false, // 
        formDataTrans: { },
        carInforList: [], // 
        rulesTrans: {},
        indexTrans: '',
        isDesc: false,

      };
    },
    created() {
    },
    methods: {
        next(){
            this.$emit("next")
        },
        back(){
            this.$emit("back")
        },
        // 运输管理措施方法
        // 添加
        addTrans(){
            this.titleTrans = '新增运输公司信息';
            this.openTrans = true
            this.isDesc = false
            this.indexTrans = null
            this.formDataTrans = {
                nameGS: '',
                userName: '',
                phone: '',
                carInfor: '',
                transLine: null,
            }
        },
        // 修改
        updateTrans(val, index){
            this.titleTrans = '修改运输公司信息';
            this.openTrans = true
            this.isDesc = false
            this.indexTrans = index
            let valForm = JSON.stringify(val)
            this.formDataTrans = JSON.parse(valForm)
        },
        // 删除
        deleteTrans(val, index){
            this.formData.tableDataTrans.splice(index, 1);
        },
        submitTrans(){
            let that = this
            console.log(this.indexTrans)
            if(this.indexTrans || this.indexTrans == 0) {
                that.formData.tableDataTrans.splice(this.indexTrans, 1, that.formDataTrans);
            } else {
                this.formData.tableDataTrans.push(this.formDataTrans)
            }
            this.openTrans = false
        },
        descTrans(){
            this.isDesc = true
        }
    }
  };
  </script>
  
  <style scoped lang="scss" >
    .app-container{
       .baAdd{
        display: flex;
        .baAddLeft{
            width: 200px;
            max-height: 350px;
        }
        .baAddRight{
            width: calc(100% - 200px);
            font-size: 14px;
            font-weight: 500;
            line-height: 20px;
            letter-spacing: 0px;

            .baAddRightBasic{
                padding-bottom: 60px;
                .basicCellTitle{
                    font-size: 24px;
                    font-weight: bold;
                    line-height: 32px;
                    padding: 10px 0;
                }
                .basicSubtitle{
                    font-size: 18px;
                    font-weight: 600;
                    line-height: 28px;
                    letter-spacing: 0px;
                    padding: 10px 0;
                }
                .basicFence{
                    width: 100%;
                    min-height: 300px;
                    border: 1px solid;
                    border-radius: 5px;
                }
            }

            .el-select{
                width: 100%;
            }
            .baAddRightBtm{
                position: fixed;
                bottom: 0;
                width: 100%;
                width: calc(100% - 230px);
                text-align: center;
                height: 50px;
                background-color: white;
                padding-top: 10px;
                box-shadow: 0 -5px 10px rgba(0, 0, 0, 0.5);
            }
        }
       } 
    }
  </style>